package com.iot08.push.service;

import com.iot08.common.entity.app.DeviceToken;
import com.iot08.common.service.base.BaseService;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @version 1.0
 * @Description:
 * @time: 2020/9/22 18:49
 * @author: Rock
 */
@Service
public class DeviceTokenService extends BaseService<DeviceToken> {

    /**
     * @param [uuid]
     * @time: 2020/9/22 18:52
     * @author: Rock
     * @version 1.0
     */
    public DeviceToken getByUuid(String uuid) {
        return this.findOne(new Query(Criteria.where("uuid").is(uuid)));
    }

    /**
     *
     * @param openid
     * @return
     */
    public DeviceToken getByOpenid(String openid) {
        return this.findOne(new Query(Criteria.where("a").is(openid)));
    }

    /**
     * @param [a]
     * @time: 2020/9/24 15:51
     * @author: Rock
     * @version 1.0
     */
    public List<DeviceToken> listByA(Set<String> a) {
        Query query = new Query(Criteria.where("a").in(a));
        query.fields().include("_id").include("mobile_type").include("uuid").include("appVersion").include("badge")
                .include("a").include("package").include("version").include("voip_devicetoken").include("haveMqtt");
        return this.find(query);
    }

}
